#include "protocol.h"
#include "crc.h"

QByteArray protocol::writeFile(char *buf, int len, Fflag flag)
{
    QByteArray package;
    package.append(HEAD);
    package.append(len);
    package.append(flag);
    package.append(buf, len);
    /* CRC */
    uint16_t crc = modbus_crc16((uint8_t *) buf, len);
    package.append(crc >> 8);
    package.append(crc & 0xff);
    return package;
}

QByteArray protocol::command(int command)
{
    QByteArray package;
    package.append(HEAD);
    package.append((char) 0);
    package.append(command);
    return package;
}

